import 'package:aichat_flutter_wallet/module/module_wallet/provider/wallet_assets_provider.dart';
import 'package:aichat_flutter_wallet/module_common/widgets/token_widget/token_logo.dart';
import 'package:aichat_flutter_wallet/module_common/widgets/token_widget/token_market_text.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:lib_database/lib_database.dart';
import 'package:lib_util/lib_util.dart';
import 'package:lib_util/utils/utils.dart';

import '../../provider/wallet_info_provider.dart';
import '../image/public_image.dart';

class Token20Widget extends StatelessWidget {
  final Token? token;
  final bool select;
  final GestureTapCallback? onTap;
  final GestureTapCallback? onLongPress;

  const Token20Widget(
      {super.key,
      required this.token,
      this.onTap,
      this.onLongPress,
      this.select = false});

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: 60.w,
      child: null == token
          ? Container()
          : InkWell(
              onTap: onTap ??
                  () {
                    // Navigator.of(context).push(MaterialPageRoute(builder: (_) {
                    //   return FungibleTokenDetailsPage(token: token!);
                    // }));
                  },
              onLongPress: onLongPress,
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  const SizedBox(
                    width: 20,
                  ),
                  Stack(
                    clipBehavior: Clip.none,
                    children: [
                      TokenLogo(
                        token: token!,
                        size: 40.w,
                      ),
                      Visibility(
                          visible: token?.contractType != TokenType.native.name,
                          child: Positioned(
                            right: -3,
                            bottom: -1,
                            child: ClipRRect(
                              borderRadius: BorderRadius.circular(16.w),
                              child: PublicImage(
                                  width: 16.w,
                                  height: 16.w,
                                  image: context
                                      .read<WalletInfoNotifier>()
                                      .walletChain!
                                      .logo),
                            ),
                          ))
                    ],
                  ),
                  SizedBox(
                    width: 10.w,
                  ),
                  Expanded(
                      child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        token!.getShowName(),
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                        style: TextStyle(
                          fontSize: 14.sp,
                          fontWeight: FontWeight.w500,
                        ),
                      ),
                      SizedBox(
                        height: 2.w,
                      ),
                      TokenMarketText(
                        token: token!,
                      )
                    ],
                  )),
                  Visibility(
                      visible:context.watch<WalletAssetsProvider>().isShowAssets,child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.end,
                    children: [
                      Text(
                          null == token!.balance
                              ? '0.00'
                              : Utils.formatStringBalance(token!.balance!,
                              fractionDigits: Config.balanceFixedNum,
                              trimDecimalZero: true),
                          textAlign: TextAlign.right,
                          style: TextStyle(
                              fontSize: 16.sp,
                              fontWeight: FontWeight.bold,
                              height: (19 / 16).w,
                              fontFamily: '_DIN',
                              color: Color.fromRGBO(51, 51, 51, 1))),
                      Text(
                          null == token!.valueusd || token!.valueusd!.isEmpty
                              ? '\$0.00'
                              : '\$${Utils.formatStringBalance(token!.valueusd!, fractionDigits: 2, trimDecimalZero: false)}',
                          textAlign: TextAlign.right,
                          style: TextStyle(
                              fontSize: 12.sp,
                              fontWeight: FontWeight.normal,
                              height: (14 / 12).w,
                              fontFamily: '_DIN',
                              color: Color.fromRGBO(190, 189, 202, 1)))
                    ],
                  )),
                  Visibility(visible: !context.watch<WalletAssetsProvider>().isShowAssets,
                      child:Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.end,
                        children: [
                          Text(
                              '****',
                              textAlign: TextAlign.right,
                              style: TextStyle(
                                  fontSize: 16.sp,
                                  fontWeight: FontWeight.bold,
                                  height: (19 / 16).w,
                                  fontFamily: '_DIN',
                                  color: Color.fromRGBO(51, 51, 51, 1))),
                          Text(
                              '****',
                              textAlign: TextAlign.right,
                              style: TextStyle(
                                  fontSize: 12.sp,
                                  fontWeight: FontWeight.normal,
                                  fontFamily: '_DIN',
                                  height: (14 / 12).w,
                                  color: Color.fromRGBO(190, 189, 202, 1)))
                        ],
                      )
                  ),
                  Visibility(
                      visible: select,
                      child: Padding(
                        padding: EdgeInsets.only(left: 14.w),
                        child: Icon(
                          token!.enable
                              ? Icons.check_circle
                              : Icons.check_circle_outline,
                          color: token!.enable ? Colors.blue : Colors.black,
                        ),
                      )),
                  SizedBox(
                    width: 20.w,
                  ),
                ],
              ),
            ),
    );
  }
}
